<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			//-------------------构造函数-------------------------------------------

			/*
			   构造函数:构建对象的函数
			   1.函数名首字母大写
			   2.不需要返回值(return)
			   3.通过 new 调用
			   
			   this:当前对象
			*/

			function Person(name, age) {
				this.name = name;
				this.age = age;
				this.study = function() {
					console.log(this.name + "学习");
				}
			}

			//创建对象
			var p1 = new Person("张三", 20);
			// console.log(p1.name);
			// p1.study();


			//------------------动态添加属性和行为--------------------------------------------------------
			p1.sex = "男";

			p1.work = function() {
				console.log("工作");
			}

			console.log(p1.sex);
			p1.work();
		</script>
	</head>
	<body>
	</body>
</html>
